/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.messaging.inbox;

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.ScrollPaneLayout;
import javax.swing.border.EmptyBorder;
import nl.cloudfarming.client.messaging.Message;

/**
 * Display Message-content in a panel.
 * @author Gerben Feenstra
 */
public class MessageDisplayContentPanel extends JPanel{
 
    /**
     * No-arg constructor
     */
    public MessageDisplayContentPanel(){
        this(null, "");
    }
    
    /**
     * No-title constructor
     * @param message The message to display
     */
    public MessageDisplayContentPanel(Message message){
        this(message, "");
    }
       
    /**
     * Construct the panel
     * @param message The message to display
     * @param title Title to display above message-content
     */
    public MessageDisplayContentPanel(Message message, String title){

        final JLabel messageLabel = new JLabel(title);
        final JTextArea messageTextContent = new JTextArea();

        if(message != null){
            messageTextContent.setText(message.getMessageText());
        }
                
        this.setLayout(new BorderLayout(5, 5));
        this.setBorder(new EmptyBorder(10, 10, 10, 10) );
       
        messageTextContent.setEditable(false);
        messageTextContent.setBackground(Color.WHITE);
        messageTextContent.setLineWrap(true);
        messageTextContent.setWrapStyleWord(true);
        messageTextContent.setCaretPosition(0);
        
        final JScrollPane scrollPane = new JScrollPane(messageTextContent);
        scrollPane.setLayout(new ScrollPaneLayout());
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        
        this.add(messageLabel, BorderLayout.NORTH);    
        this.add(scrollPane, BorderLayout.CENTER);
    }
    
}
